package com.dk.strategy;

import com.dk.config.CodePart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration
public class PartTypeFactory {

    public static Map<String, CodeStrategyHandler2> map = new HashMap<>();
    @Autowired
    List<CodeStrategyHandler2> codeStrategyHandler2List;

    //项目一启动,自动执行此方法中的逻辑
    @PostConstruct
    private void initHandler(){
        System.out.println("初始化");
        for (CodeStrategyHandler2 codeStrategyHandler2 : codeStrategyHandler2List) {
            //反射
            Class<? extends CodeStrategyHandler2> aClass = codeStrategyHandler2.getClass();
            String partType = aClass.getAnnotation(CodePart.class).partType();
            map.put(partType, codeStrategyHandler2);
        }
    }
}
